package com.example.workbook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.workbook.common.R;
import com.example.workbook.model.domain.Admin;
import com.example.workbook.model.request.AdminRequest;
import com.example.workbook.service.AdminService;
import com.example.workbook.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;

/**
* @author 53067
* @description 针对表【admin】的数据库操作Service实现
* @createDate 2023-08-09 14:26:33
*/
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin>
    implements AdminService{

    @Autowired
    private AdminMapper adminMapper;

    @Override
    public R verityPassword(AdminRequest adminRequest, HttpSession httpSession) {
        LambdaQueryWrapper<Admin> adminLambdaQueryWrapper = new LambdaQueryWrapper<>();
        adminLambdaQueryWrapper
                .eq(Admin::getName, adminRequest.getUsername())
                .eq(Admin::getPassword, adminRequest.getPassword());
        if (adminMapper.selectCount(adminLambdaQueryWrapper) > 0) {
            httpSession.setAttribute("name", adminRequest.getUsername());
            return R.success("管理员登录成功");
        } else {
            return R.error("管理员用户名或密码错误");
        }
    }
}




